<template>
   
  <div class="app-container">
    <el-card class="filter-container" shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
        <el-button
          style="float: right"
          type="primary"
          @click="handleSearchList()"
          size="small"
        >
          查询搜索
        </el-button>
        <el-button
          style="float: right; margin-right: 15px"
          @click="handleResetSearch()"
          size="small"
        >
          重置
        </el-button>
      </div>
      <div style="margin-top: 15px">
        <el-form
          :inline="true"
          :model="listQuery"
          size="small"
          label-width="140px"
        >
          <el-form-item label="输入搜索：">
            <el-input
              v-model="listQuery.id"
              class="input-width"
              placeholder="编号"
            ></el-input>
          </el-form-item>
          <el-form-item label="处理状态：">
            <el-select
              v-model="listQuery.status"
              placeholder="全部"
              clearable
              class="input-width"
            >
              <el-option
                v-for="item in statusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="售后类型：">
            <el-select
              v-model="listQuery.type"
              placeholder="全部"
              clearable
              class="input-width"
            >
              <el-option
                v-for="item in typeOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="申请时间：">
            <el-date-picker
              class="input-width"
              v-model="listQuery.createTime"
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="请选择时间"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="处理人员：">
            <el-input
              v-model="listQuery.handleMan"
              class="input-width"
              placeholder="全部"
            ></el-input>
          </el-form-item>
          <el-form-item label="处理时间：">
            <el-date-picker
              class="input-width"
              v-model="listQuery.handleTime"
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="请选择时间"
            >
            </el-date-picker>
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
    </el-card>
    <div class="table-container">
       <!-- @selection-change="handleSelectionChange" -->
      <el-table
        ref="returnApplyTable"
        :data="list"
        style="width: 100%"
       
        v-loading="listLoading"
        border
      >
        <!-- <el-table-column
          type="selection"
          width="60"
          align="center"
        ></el-table-column> -->
        <el-table-column label="编号" width="180" align="center">
          <template slot-scope="scope">{{ scope.row.id }}</template>
        </el-table-column>
        <el-table-column label="申请时间" width="180" align="center">
          <template slot-scope="scope">{{
            scope.row.createTime | formatTime
          }}</template>
        </el-table-column>
        <el-table-column label="用户账号" align="center">
          <template slot-scope="scope">{{ scope.row.memberUsername }}</template>
        </el-table-column>
        <el-table-column label="退款金额" width="180" align="center">
          <template slot-scope="scope">￥{{ scope.row.returnAmount }}</template>
        </el-table-column>
        <!-- <el-table-column label="实际退款金额" width="180" align="center" >
                  <template slot-scope="scope" v-if="scope.row.refundStatus==1">￥{{scope.row.returnAmount}}</template>
                </el-table-column>
        <el-table-column label="商品金额" width="180" align="center">
          <template slot-scope="scope">￥{{scope.row | formatReturnAmount}}</template>
        </el-table-column> -->
        <el-table-column label="处理状态" width="180" align="center">
          <template slot-scope="scope">{{
            scope.row.status | formatStatus
          }}</template>
        </el-table-column>
        <el-table-column label="售后类型" width="180" align="center">
          <template slot-scope="scope">{{
            scope.row.type | formatType
          }}</template>
        </el-table-column>
        <el-table-column label="处理人员" width="180" align="center">
          <template slot-scope="scope">{{
            scope.row.handleMan
          }}</template>
        </el-table-column>
        <el-table-column label="处理时间" width="180" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.handleTime">{{
              scope.row.handleTime | formatTime
            }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="180" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleViewDetail(scope.$index, scope.row)"
              >处理详情</el-button
            >

            <el-button
              v-if="scope.row.status == 10"
              size="mini"
              @click="handleShowVeriyEditDialog(scope.$index, scope.row)"
              >审核
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize"
        :page-sizes="[10, 15, 50]"
        :total="total"
      >
      </el-pagination>
    </div>
    <el-dialog
      title="审核信息"
      :visible.sync="vertyProduct.dialogVisible"
      width="40%"
    >
      <el-form :model="vertyProduct" ref="brandFrom" label-width="150px">
        <el-form-item label="审核状态：" prop="status">
          <el-radio-group v-model="vertyProduct.status">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="3">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="审核备注：" prop="handleNote">
          <el-input v-model="vertyProduct.handleNote"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button @click="vertyProduct.dialogVisible = false"
            >取 消</el-button
          >
          <el-button type="primary" @click="handleEditVConfirm"
            >确 定</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { formatDate } from "@/utils/date";
import { fetchList, deleteApply, updateApplyStatus } from "@/api/returnApply";
const defaultListQuery = {
  pageNum: 1,
  pageSize: 10,
  id: null,
  receiverKeyword: null,
  status: null,
  createTime: null,
  handleMan: null,
  handleTime: null,
};
const defaultStatusOptions = [
  {
    label: "待处理",
    value: 0,
  },
  {
    label: "处理中",
    value: 1,
  },
  {
    label: "已完成",
    value: 2,
  },
  {
    label: "已拒绝",
    value: 3,
  },
  // {
  //   label: '待处理',
  //   value: 0
  // },
  // {
  //   label: '处理中',
  //   value: 1
  // },
  // {
  //   label: '已完成',
  //   value: 2
  // },
  // {
  //   label: '已拒绝',
  //   value: 3
  // }
];
const defaultTypeOptions = [
  {
    label: "换货",
    value: 0,
  },
  {
    label: "仅退款",
    value: 1,
  },
  {
    label: "退货退款",
    value: 2,
  },
];
export default {
  name: "returnApplyList",
  data() {
    return {
      listQuery: Object.assign({}, defaultListQuery),
      statusOptions: Object.assign({}, defaultStatusOptions),
      typeOptions: Object.assign({}, defaultTypeOptions),
      list: null,
      total: null,
      listLoading: false,
      multipleSelection: [],
      operateType: 1,
      vertyProduct: {
        dialogVisible: false,
        id: null,
        handleNote: "",
        status: null,
      },
      operateOptions: [
        {
          label: "批量删除",
          value: 1,
        },
      ],
    };
  },
  created() {
    this.getList();
  },
  filters: {
    formatTime(time) {
      if (time == null || time === "") {
        return "N/A";
      }
      let date = new Date(time);
      return formatDate(date, "yyyy-MM-dd hh:mm:ss");
    },
    formatStatus(status) {
      for (let i = 0; i < defaultStatusOptions.length; i++) {
        if (status === defaultStatusOptions[i].value) {
          return defaultStatusOptions[i].label;
        }
      }
    },
    formatType(status) {
      for (let i = 0; i < defaultTypeOptions.length; i++) {
        if (status === defaultTypeOptions[i].value) {
          return defaultTypeOptions[i].label;
        }
      }
    },
    formatReturnAmount(row) {
      return row.productRealPrice + "X" + row.productCount;
    },
  },
  methods: {
    handleEditVConfirm() {
      if (this.vertyProduct.handleNote == null) {
        this.$message({
          message: "暂无审核信息",
          type: "warning",
          duration: 1000,
        });
        return;
      }
      this.$confirm("是否要进行审核", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let params = new URLSearchParams();

        params.append("id", this.vertyProduct.id);
        params.append("status", this.vertyProduct.status);
        params.append("orderId", this.vertyProduct.orderId);
        params.append("handleNote", this.vertyProduct.handleNote);
        updateApplyStatus(params).then((response) => {
          this.$message({
            message: "修改成功",
            type: "success",
            duration: 1000,
          });
          this.getList();
        });
        this.vertyProduct.dialogVisible = false;
      });
    },
    handleShowVeriyEditDialog(index, row) {
      this.vertyProduct.dialogVisible = true;
      this.vertyProduct.id = row.id;
      this.vertyProduct.orderId = row.orderId;
      this.vertyProduct.status = row.status;
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    handleResetSearch() {
      this.listQuery = Object.assign({}, defaultListQuery);
    },
    handleSearchList() {
      this.listQuery.pageNum = 1;
      this.getList();
    },
    handleViewDetail(index, row) {
      this.$router.push({
        path: "/oms/returnApplyDetail",
        query: { id: row.id },
      });
    },
    handleBatchOperate() {
      if (this.multipleSelection == null || this.multipleSelection.length < 1) {
        this.$message({
          message: "请选择要操作的申请",
          type: "warning",
          duration: 1000,
        });
        return;
      }
      if (this.operateType === 1) {
        //批量删除
        this.$confirm("是否要进行删除操作?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          let params = new URLSearchParams();
          let ids = [];
          for (let i = 0; i < this.multipleSelection.length; i++) {
            ids.push(this.multipleSelection[i].id);
          }
          params.append("ids", ids);
          deleteApply(params).then((response) => {
            this.getList();
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
        });
      }
    },
    handleSizeChange(val) {
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNum = val;
      this.getList();
    },
    getList() {
      if (this.$route.query.orderId && this.$route.query.orderId > 0) {
        this.listQuery.orderId = this.$route.query.orderId;
      }

      this.listLoading = true;
      fetchList(this.listQuery).then((response) => {
        this.listLoading = false;
        this.list = response.data.records;
        this.total = response.data.total;
      });
    },
  },
};
</script>
<style scoped>
.input-width {
  width: 203px;
}
</style>


